import axios from "axios";
import { Operation } from '@/api';

// 加载
const load_oper_list = async (context, payload) => {
    let { status, data } = await axios.get('/operation/list', { params: payload });
    if (status) {
        context.commit("UPDATE_OPERATION", data);
    }
}

// 添加
const insert_oper=async (context,payload)=>{
    let {status,msg,data}=await axios.post('/operation',payload);
    if(status){
        context.commit("INSERT_OPERATION",{...data,...payload})
    }
    return {status,msg,data}
}

// 修改
const edit_oper=async (context,payload)=>{
    let {operation_id}=payload;
    let {status,msg}=await Operation.edit(operation_id,payload);
    return {status,msg}
}

const remove_oper=async (context, payload) => {
    console.log(payload);
    let { status, msg,data } = await Operation.remove(payload.operation_id);
    if (status) {
        context.commit("REMOVE_OPERATION", payload.index);
    }
    return { status, msg,data }
}


export default {
    load_oper_list,
    insert_oper,
    edit_oper,
    remove_oper
}